package com.hghivln.blog.controller;


import com.hghivln.blog.common.lang.Result;
import com.hghivln.blog.entity.BlogComment;
import com.hghivln.blog.pojo.dto.BlogCommentDto;
import com.hghivln.blog.service.BlogCommentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 博客评论表 前端控制器
 * </p>
 *
 * @author hghivln
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/blog-comment")
public class BlogCommentController {

    @Autowired
    private BlogCommentService blogCommentService;

    /**
     * 保存评论
     */
    @PostMapping("/save")
    public Result<?> save(@RequestBody BlogComment blogComment) {
        blogCommentService.saveComment(blogComment);
        return new Result<>(blogComment.getId());
    }

    /**
     * 根据博客ID 查询评论
     */
    @PostMapping("/getByBlogId")
    public Result<?> getByBlogId(@RequestBody BlogCommentDto blogCommentDto) {
        return blogCommentService.getByBlogId(blogCommentDto);
    }

    /**
     * 分页查询
     */
    @PostMapping("/getByPage")
    public Result<?> getByPage(@RequestBody BlogCommentDto blogCommentDto) {
        return blogCommentService.getByPage(blogCommentDto);
    }

    /**
     * 删除评论
     */
    @DeleteMapping("/deleteById/{id}")
    public Result<?> deleteComment(@PathVariable Long id) {
        blogCommentService.deleteComment(id);
        return new Result<>("删除成功！");
    }
}
